package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;

import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.PartitionVLANAttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 *
 */
@Service
@AttrHandler(PartitionVLANAttrHandler.class)
public class PartitionVLANAttrLinkHandler extends AbstractAttrLinkageHandler<AttrData> {

    @Override
    public void handle(KiteAttr attr, KiteInst inst, AttrData data) {
        KiteAttr vlanCodeAttr = inst.getAttr("2_0000145"); // VLAN号
        KiteAttr vlanPatternAttr = inst.getAttr("2_0000034"); // VLAN模式
        // 当是否划分VLAN为是时 VLAN号, VLAN模式必填
        if ("1_0000106".equals(attr.getValue())) {
            if (Objects.nonNull(vlanCodeAttr)) {
                vlanCodeAttr.setIsNull(KeyConsts.is_CROSS_DOMAIN_F);
                vlanCodeAttr.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_D);
            }
            if (Objects.nonNull(vlanPatternAttr)) {
                vlanPatternAttr.setIsNull(KeyConsts.IS_CROSS_DOMAIN_T);
                vlanPatternAttr.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_D);
            }
        } else {
            if (Objects.nonNull(vlanCodeAttr)) {
                vlanCodeAttr.setIsNull(KeyConsts.IS_CROSS_DOMAIN_T);
                vlanCodeAttr.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_E);
            }
            if (Objects.nonNull(vlanPatternAttr)) {
                vlanPatternAttr.setIsNull(KeyConsts.IS_CROSS_DOMAIN_T);
                vlanPatternAttr.setShowType(KeyConsts.PROD_ATTR_SHOW_TYPE_E);
            }
        }
    }

    @Override
    public void handleStyle(KiteAttr attr, KiteInst inst, AttrData data) {

    }
}
